package com.yuexunit.operationman.nbsy.module.InterventionalOperation.adapter;

import android.view.View;
import android.widget.AbsListView;
import android.widget.TextView;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.Bean.DrugBean;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by chenss on 2017/8/17 0017.
 */

public class DrugListAdapter extends KJAdapter<DrugBean> {

    ArrayList<DrugBean> mDatas = new ArrayList<>();

    public DrugListAdapter(AbsListView view, Collection<DrugBean> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
        this.mDatas = (ArrayList<DrugBean>)mDatas;
    }

    public ArrayList<DrugBean> getmDatas()
    {
        return mDatas;
    }

    @Override
    public void convert(AdapterHolder helper, final DrugBean item, boolean isScrolling, int position) {
        helper.setText(R.id.name,item.getName());
        if(item.getStartTime()!=null&&item.getStartTime().length()>0)
        {
            helper.setText(R.id.startTime, "注射开始时间：" + item.getStartTime());
        }
        else {
            helper.setText(R.id.startTime, "注射开始时间：");
        }
        if(item.getEndTime()!=null&&item.getEndTime().length()>0) {
            helper.setText(R.id.endTime, "注射结束时间：" + item.getEndTime());
        }
        else
        {
            helper.setText(R.id.endTime, "注射结束时间：");
        }
        TextView delete = helper.getView(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDatas.remove(item);
                notifyDataSetChanged();
            }
        });
    }
}
